/*
 * @Description:
 * @Author: maskMan
 * @LastEditTime: 2024-11-14 12:44:59
 */
const path = require("path");
const name = "Vue Typescript Admin";

module.exports = {
  // TODO: Remember to change publicPath to fit your need
  publicPath:
    process.env.NODE_ENV === "production"
      ? "/vue-typescript-admin-template/"
      : "/",
  lintOnSave: process.env.NODE_ENV === "development",
  pwa: {
    name: name,
  },
  devServer: {
    open: true, // 自动打开浏览器
    hot: true, // 启用热重载
  },
  configureWebpack: {
    optimization: {
      splitChunks: false, // 禁用代码拆分
    },
  },
  css: {
    sourceMap: true, // 启用 CSS source maps
  },
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "scss",
      patterns: [
        path.resolve(__dirname, "src/styles/_variables.scss"),
        path.resolve(__dirname, "src/styles/_mixins.scss"),
      ],
    },
  },
  chainWebpack(config) {
    // provide the app's title in html-webpack-plugin's options list so that
    // it can be accessed in index.html to inject the correct title.
    // https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-plugin
    config.optimization.splitChunks(false); // 禁用代码拆分
    if (process.env.NODE_ENV === "development") {
      config.mode = "development"; // 开发模式
      config.devtool("source-map"); // 启用 source-map
    }
    // 如果是生产环境
    else if (process.env.NODE_ENV === "production") {
      config.mode = "production"; // 生产模式
      config.devtool("hidden-source-map"); // 生产环境不显示源代码
    }

    config.plugin("html").tap((args) => {
      args[0].title = name;
      return args;
    });
    config.module.rule("js").exclude.add(/node_modules/); // 排除 node_modules 文件夹中的 JavaScript 文件
    config.module
      .rule("vue")
      .use("vue-loader")
      .loader("vue-loader")
      .tap((options) => {
        // 保证在开发模式下不进行压缩
        options.compilerOptions = {
          preserveWhitespace: false, // 去除空白字符
        };
        return options;
      });
  },
};
